package com.jf.spring.factory;

import com.jf.spring.bean.Student;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-10-22
 * Time:21:10
 */
public class FactoryBean implements org.springframework.beans.factory.FactoryBean<Student> {
    private String name;
    private Map<String ,Student> students;
    {
        students = new HashMap<>();
        students.put("s1", new Student((1)));
        students.put("s2",new Student((2)));
        students.put("s3",new Student((3)));
        students.put("s4",new Student((4)));
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<String, Student> getStudents() {
        return students;
    }

    public void setStudents(Map<String ,Student> students) {
        this.students = students;
    }

    @Override
    public Student getObject() throws Exception {
        return students.get(name);
    }

    @Override
    public Class<?> getObjectType() {
        return Student.class;
    }
}
